clear
use rental_subsidy_value, replace

gen LIU=liunits
gen DRSU=rentalsubsidyunits
gen RI=rentalincome_real
gen RST=realrentalsubsidytotal/12

*Total Tenant Rent Unsubsidized
gen TTRU=(LIU-DRSU)*(RI/LIU)
*Total Tenant Rent Subsidized
gen TTRS=.27*(RI+RST-TTRU)
*Total Tenant Rent
gen TTR=TTRU+TTRS
*Total Rental Assistance
gen TRA=RI+RST-TTR


*****************************
*Assumptions from HUD and CPS
*****************************
*Assume TRA increases by 3.5% each year


*Use this comment to create tables for four and nine percent credit projects, or construction type separately (used to create Table 4)
*keep if nineper==1
*keep if constructiontype=="A&R"

foreach x in treasury30 marketratemean  {
gen `x'_monthly=`x'/12
gen A_`x'_TRAgrowth=(1+(.035/12))/(1+`x'_monthly)

}

foreach x in treasury30 marketratemean  {
gen PV_TRA_`x'=(TRA*(1-A_`x'_TRAgrowth^360))/(1-A_`x'_TRAgrowth)
}
sum PV* LIU

collapse (sum) PV* LIU

foreach y in treasury30 marketratemean  {
gen PV_TRA_`y'_LIU=PV_TRA_`y'/LIU
}

keep PV*LIU
format %16.0g *
sum *
browse



